<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

/**
 * 批量修改状态
 */
class StatusAction extends BatchAction
{
    public $id;

    public function __construct($id = '')
    {
        $this->id = $id;
        $this->script();
    }

    public function script()
    {
        $script = <<<EOF

        var url = '{$this->resource}/status';
        //正常
        $(".grid-batch-1").on('click',function(){
        	var ids = selectedRows();
        	batch(0,ids,url);
        });
        //测试
        $(".grid-batch-2").on('click',function(){
        	var ids = selectedRows();
        	batch(10000,ids,url);
        });
        //修改端口
        $(".grid-batch-3").on('click',function(){
            var ids = selectedRows();
            if(ids != ''){
               $('#port-modal').modal();
           }
        });
        //提交修改端口
        $("#port-submit").on('click',function(){
            var port = $("#port").val();
            if(!port){
                toastr.error('请输入端口号');return;
            }
            var ids = selectedRows();
                var param = {
                    type:'post',
                    url:'{$this->resource}/changePort',
                    data:{
                         _token:LA.token,
                         ids:ids,
                         port:port
                    },
                    success:function(data){
                         $.pjax.reload('#pjax-container');
                         $(".close").click();
                         toastr.success(data.message);
                    }
            };
             ajaxHttp(param);


        });
EOF;

        return $script;
    }
}
